package main

import (
	"fmt"
)

func fibonacci(n int, c chan int) {
	x, y := 1, 1

	for i := 0; i < n; i++ {
		c <- x
		x, y = y, x+y
	}

	close(c) // 在 producer 关闭 channel
}

func main() {
	c := make(chan int, 10)
	go fibonacci(cap(c), c)
	for i := range c {
		fmt.Println(i)
	}
	_, ok := <-c // 从 closed channel 取值 会得到 对应元素的 零值 ok = false
	if !ok {
		fmt.Println("channel c already closed")
	}

}
